// +build linux darwin

package mprotect

import "syscall"

func ModifyProtection(addr uintptr, enableWrite bool) {

	start := addr & ^uintptr(syscall.Getpagesize()-1)

	prot := syscall.PROT_READ
	if enableWrite {
		prot |= syscall.PROT_WRITE
	}
	_, _, err := syscall.Syscall(
		syscall.SYS_MPROTECT,
		start, uintptr(syscall.Getpagesize()),
		uintptr(prot),
	)
	if err != 0 {
		panic("syscall failed: " + err.Error())
	}
}
